function ranks = make_final_prediction(model, example)
% Uses your trained model to make a final prediction for a SINGLE example.
%
% Usage:
%
%   RANKS = MAKE_FINAL_PREDICTION(MODEL, EXAMPLE);
%
% This is the function that we will use for checkpoint evaluations and the
% final test. It takes your trained model (output from INIT_MODEL) and a SINGLE 
% example, and returns a ranking ROW VECTOR as explained in the project
% overview.
%
% This function SHOULD NOT DO ANY TRAINING. This code needs to run in under
% 5 minutes. Your model should be loaded from disk in INIT_MODEL. DO NOT DO
% ANY TRAINING HERE.
train_data = model.train_data; 
example = make_lyrics_sparse(example, model.vocab); %grab the feature vector

%scale the feature vector by our best guess
%  (min/max of the train and quiz data)
load('scale_factors.mat');
example = (example - repmat(scale_min,size(example,1),1))* ...
    spdiags(1./(scale_max-scale_min)',0,size(example,2),size(example,2));


% compute intersection kernel with example
Ktest = kernel_intersection(train_data, example);

% get probabilities from libsvm's svmpredict
[~, ~, probability] = svmpredict(1, ...
    [(1:size(Ktest,1))' Ktest], model.svm, '-b 1');

% order probabilties correctly
ordered_prob = zeros(size(probability)); 
ordered_prob(:,model.svm.Label) = probability; 

% return ranks
ranks = get_ranks(ordered_prob); 
